﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Beetle.Sl.EditorControl.Core;

namespace Beetle.Sl.EditorControl.ToolBars.SetFontBold
{
    [ToolBarItemAttribute]
    public class SetFontBoldToolBar : ToolBarItem
    {
        public const string COMMANDTEXT = "SetFontStyle";
        public override string Name
        {
            get
            {
                return "SetFontBold";
            }
        }

        public SetFontBoldToolBar()
        {
            this.ImageButtonUri = new Uri("/Beetle.Sl.EditorControl;component/ToolBars/SetFontBold/Bold.png", UriKind.Relative);
        }

        public override void OnCommand(object arg)
        {
            this.IsSelected = !this.IsSelected;
            this.Editor.ExcuteCommand(SetFontBoldToolBar.COMMANDTEXT, new object[] { Run.FontWeightProperty, this.IsSelected ? FontWeights.Bold : FontWeights.Normal });
        }

        public override void UpdateVisual()
        {
            if (this.Editor.RichTextBoxInst.IsReadOnly)
            {
                this.IsSelected = false;
                this.IsEnabled = false;
                return;
            }
            else
            {
                this.IsEnabled = true;
            }

            if (this.Editor.RichTextBoxInst.Selection.GetPropertyValue(Run.FontWeightProperty) is FontWeight
                && ((FontWeight)this.Editor.RichTextBoxInst.Selection.GetPropertyValue(Run.FontWeightProperty)) == FontWeights.Bold)
            {
                this.IsSelected = true;
            }
            else
            {
                this.IsSelected = false;
            }
        }
    }
}
